<template>
  <el-container>
    <el-aside>
      <SideMenu></SideMenu>
    </el-aside>
    <el-container>
      <el-header style="color: white">
        <strong>VueAdmin后台管理系统</strong>
        <div class="header-avatar">
          <el-avatar size="medium" :src="userInfo.avatar"></el-avatar>
          <el-dropdown>
            <span class="el-dropdown-link" style="color: white">
              {{ userInfo.username }}<i class="el-icon-arrow-down el-icon--right"></i></span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item><router-link to="/sys/userCenter">个人中心</router-link></el-dropdown-item>
              <el-dropdown-item @click.native="logout">退出</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <el-link href="https://www.youtube.com/" style="color: white" target="_blank">youtube</el-link>
          <el-link href="https://www.bilibili.com/" style="color: white" target="_blank">B站</el-link>
        </div>
      </el-header>
      <el-main>
        <Tabs></Tabs>
        <div style="margin: 0 15px">
          <router-view></router-view>
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import SideMenu from "./ins/SideMenu";
import Tabs from "./ins/Tabs";

export default {
  name: "Home",
  components: {
    SideMenu,
    Tabs
  },
  data() {
    return {
      userInfo: {
        id: "",
        username: "",
        avatar: ""
      }
    }
  },
  created() {
    this.getUserInfo();
  },
  methods: {
    getUserInfo() {
      this.$axios.get('/sys/userInfo').then(res => {
        console.log(res);
        this.userInfo = res.data.data.userInfo;
      }).catch(err => {
        console.log(err)
      })
    },
    logout() {
      this.$axios.post('/logout').then(res => {
        if (res.data.code === 200) {
          localStorage.clear()
          sessionStorage.clear()
          this.$store.commit('RESET_STATE')
          this.$router.push('/login')
        }
      })
    }
  }
}
</script>

<style scoped>
.el-container {
  margin: 0;
  padding: 0;
  height: 100%;
}

.header-avatar {
  float: right;
  width: 210px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.el-header {
  background-color: rgb(85, 179, 255);
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #D3DCE6;
  color: #333;
  line-height: 200px;
  width: 210px!important;
}

.el-main {
  background-color: #E9EEF3;
  color: #333;
  padding: 0!important;
}

.el-dropdown-link {
  cursor: pointer;
}

</style>
